<?php

class Web extends CI_Controller{

	function __construct(){
		parent::__construct();
		$this->load->model('web_model');
		$this->load->helper('share');
		$this->load->library('pagination');
	}
	
	function index(){
		$data['info'] = $this->web_model->getAllInfo();
		$data['agenda'] = $this->web_model->getAllAgenda();
		$data['agenda1'] = $this->web_model->getLimitAgenda();
		$data['berita'] = $this->web_model->getBerita();
		$data['slider'] = $this->web_model->getSlider();
		$data['divisi'] = $this->web_model->getDivisi();
		$data['materi'] = $this->web_model->getMateri();
		$data['menu'] = $this->web_model->getMenu();
		
		$this->load->view('web/top', $data);
		$this->load->view('web/slider', $data);
		$this->load->view('web/sidebar_left', $data);
		$this->load->view('web/content', $data);
		$this->load->view('web/sidebar_right', $data);
		$this->load->view('web/footer');
	}
	
	function detailberita(){
		$id = $this->uri->segment(3);
		$data['info'] = $this->web_model->getAllInfo();
		$data['detail'] = $this->web_model->getDetailBerita($id);
		$data['berita'] = $this->web_model->getAllBerita();
		$data['agenda'] = $this->web_model->getAllAgenda();
		$data['divisi'] = $this->web_model->getDivisi();
		$data['materi'] = $this->web_model->getMateri();
		$data['menu'] = $this->web_model->getMenu();
		
		$this->load->view('web/top', $data);
		$this->load->view('web/sidebar_left', $data);
		$this->load->view('web/detail_berita', $data);
		//$this->load->view('web/sidebar', $data);
		$this->load->view('web/footer');
	}
	
	function detailagenda(){
		$id = $this->uri->segment(3);
		$data['info'] = $this->web_model->getAllInfo();
		$data['detail'] = $this->web_model->getDetailAgenda($id);
		$data['berita'] = $this->web_model->getAllBerita();
		$data['agenda'] = $this->web_model->getAllAgenda();
		$data['divisi'] = $this->web_model->getDivisi();
		$data['materi'] = $this->web_model->getMateri();
		$data['menu'] = $this->web_model->getMenu();
		
		$this->load->view('web/top', $data);
		$this->load->view('web/sidebar_left', $data);
		$this->load->view('web/detail_agenda', $data);
		//$this->load->view('web/sidebar', $data);
		$this->load->view('web/footer');
	}
	
	function detailinfo(){
		$id = $this->uri->segment(3);
		$data['info'] = $this->web_model->getAllInfo();
		$data['detail'] = $this->web_model->getDetailInfo($id);
		$data['berita'] = $this->web_model->getAllBerita();
		$data['agenda'] = $this->web_model->getAllAgenda();
		$data['divisi'] = $this->web_model->getDivisi();
		$data['materi'] = $this->web_model->getMateri();
		$data['menu'] = $this->web_model->getMenu();
		
		$this->load->view('web/top', $data);
		$this->load->view('web/sidebar_left', $data);
		$this->load->view('web/detail_info', $data);
		//$this->load->view('web/sidebar', $data);
		$this->load->view('web/footer');
	}
	
	function visimisi(){
		$data['info'] = $this->web_model->getAllInfo();
		$data['divisi'] = $this->web_model->getDivisi();
		$data['agenda'] = $this->web_model->getAllAgenda();
		$data['materi'] = $this->web_model->getMateri();
		$data['menu'] = $this->web_model->getMenu();
		
		$this->load->view('web/top', $data);
		$this->load->view('web/sidebar_left', $data);
		$this->load->view('web/visimisi');
		$this->load->view('web/footer');
	}
	
	function profil(){
		$data['info'] = $this->web_model->getAllInfo();
		$data['divisi'] = $this->web_model->getDivisi();
		$data['agenda'] = $this->web_model->getAllAgenda();
		$data['materi'] = $this->web_model->getMateri();
		$data['menu'] = $this->web_model->getMenu();
		
		$this->load->view('web/top', $data);
		$this->load->view('web/sidebar_left', $data);
		$this->load->view('web/profil');
		$this->load->view('web/footer');
	}
	
	function carimember(){	
		$term = $this->input->post('keyword',TRUE);	
		$rows = $this->web_model->cariMember($term);//ambil data dari database
		$data = array();
		foreach ($rows as $row)
		{
		  $data[] = array(
		  	'nim' => $row["nim"],
			'nama' => $row["nama"],
			'divisi' => $row["divisi"]
			);//menyimpan hasil yang ditemukan di array
		}
		echo json_encode($data);//konversi array ke json
	//jangan lupa libraries databasenya di load juga, biasanya di file autoload

	}
	
	function download(){
		$file = $this->uri->segment(3);
		$data = file_get_contents("./image/materi/".$file); // Read the file's contents
		$name = $file;
		force_download($name, $data);
	}
	
	
	function pemilihanDivisi(){
		$data['info'] = $this->web_model->getAllInfo();
		$data['divisi'] = $this->web_model->getDivisi();
		$data['agenda'] = $this->web_model->getAllAgenda();
		$data['materi'] = $this->web_model->getMateri();
		$data['menu'] = $this->web_model->getMenu();
		
		$this->load->view('web/top', $data);
		$this->load->view('web/sidebar_left', $data);
		$this->load->view('web/pilih_divisi', $data);
		$this->load->view('web/footer');
	}
	
	function insertPilihDivisi(){
		$this->load->library('form_validation');
		
		$this->form_validation->set_rules('nim', 'NIM', 'required');
		$this->form_validation->set_rules('nama', 'Nama', 'required');
		$this->form_validation->set_rules('hp', 'Hanpdhone', 'required');
		$this->form_validation->set_rules('kelas', 'Kelas', 'required');
		$this->form_validation->set_rules('sekolah', 'Sekolah', 'required');
		$this->form_validation->set_rules('jurusan', 'Jurusan', 'required');
		$this->form_validation->set_rules('harapan', 'Ini ', 'required');
		$this->form_validation->set_rules('divisi', 'Divisi ', 'required');
		
		$this->form_validation->set_message('required','Field %s Harus di Isi');
		
		if($this->form_validation->run()==TRUE){
			$nim = mysql_real_escape_string($this->input->post('nim'));
			$nama = mysql_real_escape_string($this->input->post('nama'));
			$hp = mysql_real_escape_string($this->input->post('hp'));
			$kelas = mysql_real_escape_string($this->input->post('kelas'));
			$jurusan = mysql_real_escape_string($this->input->post('jurusan'));
			$sekolah =  mysql_real_escape_string($this->input->post('sekolah'));
			$jur_sekolah = mysql_real_escape_string($this->input->post('jur_sekolah'));
			$divisi = mysql_real_escape_string($this->input->post('divisi'));
			$laptop = mysql_real_escape_string($this->input->post('laptop'));
			$materi = mysql_real_escape_string($this->input->post('materi'));
			$harapan = mysql_real_escape_string($this->input->post('harapan'));
			
			$this->web_model->insert_pildiv($nim,$nama,$hp,$kelas,$jurusan,$sekolah,$jur_sekolah,$divisi,$laptop,$materi,$harapan);
			redirect('web');
		}else{
			$data['info'] = $this->web_model->getAllInfo();
			$data['divisi'] = $this->web_model->getDivisi();
			$data['agenda'] = $this->web_model->getAllAgenda();
			$data['materi'] = $this->web_model->getMateri();
			$data['menu'] = $this->web_model->getMenu();
			
			$this->load->view('web/top', $data);
			$this->load->view('web/sidebar_left', $data);
			$this->load->view('web/pilih_divisi', $data);
			$this->load->view('web/footer');
		}
	}
	
	function search(){
		$judul = $this->input->post('judul');
		$table = $this->web_model->getAllBerita();
		
		$config['uri_segment'] = 3;
		$config['total_rows'] = count($table);
		$config['per_page'] = 10;
		$config['base_url'] = base_url() . 'web/search/';
			
		$this->pagination->initialize($config);
		
		$data['pagination'] = $this->pagination->create_links();
		$data['info'] = $this->web_model->getAllInfo();
		//$data['berita'] = $this->web_model->getAllBerita();
		$data['agenda'] = $this->web_model->getAllAgenda();
		$data['divisi'] = $this->web_model->getDivisi();
		$data['materi'] = $this->web_model->getMateri();
		$data['menu'] = $this->web_model->getMenu();
		$data['tabel'] = $this->web_model->search($judul,$config['per_page'], $this->uri->segment(3));
		$data['keyword'] = $judul;
		
		$this->load->view('web/top', $data);
		$this->load->view('web/sidebar_left', $data);
		$this->load->view('web/pencarian', $data);
		//$this->load->view('web/sidebar', $data);
		$this->load->view('web/footer');
	}
	
	function elearning(){
		$id=$this->uri->segment(3);
		
		$data['info'] = $this->web_model->getAllInfo();
		$data['divisi'] = $this->web_model->getDivisi();
		$data['agenda'] = $this->web_model->getAllAgenda();
		$data['materi'] = $this->web_model->getMateri();
		$data['menu'] = $this->web_model->getMenu();
		$data['elearning'] = $this->web_model->getElearning($id);
		$data['keyword'] = $this->uri->segment(4);

		
		$this->load->view('web/top', $data);
		$this->load->view('web/sidebar_left', $data);
		$this->load->view('web/elearning', $data);
		$this->load->view('web/footer');
	}
	
	function comingsoon(){
		$this->load->view('comingsoon');
	}
	
	function berita(){
		$table = $this->web_model->getAllBerita();
		
		$config['uri_segment'] = 3;
		$config['total_rows'] = count($table);
		$config['per_page'] = 2;
		$config['base_url'] = base_url() . 'web/berita/';
			
		$this->pagination->initialize($config);
		
		$data['pagination'] = $this->pagination->create_links();
		$data['info'] = $this->web_model->getAllInfo();
		$data['divisi'] = $this->web_model->getDivisi();
		$data['agenda'] = $this->web_model->getAllAgenda();
		$data['materi'] = $this->web_model->getMateri();
		$data['menu'] = $this->web_model->getMenu();
		$data['berita'] = $this->web_model->getBeritaByPage($config['per_page'], $this->uri->segment(3));

		
		$this->load->view('web/top', $data);
		$this->load->view('web/sidebar_left', $data);
		$this->load->view('web/semua_berita', $data);
		$this->load->view('web/footer');
	}
	
	function gallery(){
		$data['info'] = $this->web_model->getAllInfo();
		$data['divisi'] = $this->web_model->getDivisi();
		$data['agenda'] = $this->web_model->getAllAgenda();
		$data['materi'] = $this->web_model->getMateri();
		$data['menu'] = $this->web_model->getMenu();
		
		$this->load->view('web/top', $data);
		$this->load->view('web/sidebar_left', $data);
		$this->load->view('web/gallery', $data);
		$this->load->view('web/footer');
	}

}
?>